package com.leyou.favorite.controller;

import com.leyou.favorite.Favorite;
import com.leyou.favorite.FavoriteDto;
import com.leyou.favorite.service.FavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
@Controller
public class FavoriteController {
    @Autowired
    private FavoriteService favoriteService;

    @PostMapping("/sku/addFavorite")
    public ResponseEntity<Void> addFavorite(@RequestBody Favorite favorite){
        System.out.println(favorite);
        favoriteService.addFavorite(favorite);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    @DeleteMapping("/sku/delFavorite/{skuId}")
    public ResponseEntity<Void> deleteFavorite(@PathVariable("skuId") Long skuId) {
        System.out.println(skuId);
        favoriteService.deleteFavorite(skuId);
        return ResponseEntity.ok().build();
    }

    @GetMapping("/sku/findFavoriteStatus")
    public ResponseEntity<Integer> findFavoriteStatus(@RequestParam("skuId") Long skuId){
        Integer state = favoriteService.findFavoriteStatus(skuId);
        return ResponseEntity.ok(state);
    }

    @GetMapping("/sku/findAllFavorite")
    public ResponseEntity<List<FavoriteDto>> findAllFavorite(){
        List<FavoriteDto> favoriteList = favoriteService.findAllFavorite();
        return ResponseEntity.ok(favoriteList);
    }


}
